<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script type="text/javascript">
        var obj = {
            name: "smyhvae",
            age: 26,
            gender: "男",
            address: "shenzhen",
            sayHi: function() {
                console.log(this.name);
            }
        };
        //遍历对象的属性
        for (var key in obj) {
            console.log("属性名：" + key);
            console.log("属性值:" + obj[key]); // 注意，因为这里的属性名 key 是变量，所以，如果想获取属性值，不能写成 obj.key，而是要写成 obj[key]
        }
    </script>
</body>

</html>